console.log('---------------------------------------防抖节流-------------------------------------------')


// 防抖
function debounce(fn, time) {
    let timer = null
    return function () {
        clearTimeout(timer)
        timer = setTimeout(() => {
            fn.apply(this, arguments)
        }, time)
    }
}
var debo = document.getElementById("debounce")
const de = () => { console.log('我是防抖') }
debo.addEventListener('mousemove', fangdou(de, 1000))

// 节流
function throttle(fn, time) {
    let flag = true;
    return function () {
        if (!flag) return
        flag = false
        fn.apply(this, arguments)
        setTimeout(() => {
            flag = true
        }, time)
    }
}

var thro = document.getElementById("throttle")
const th = () => { console.log('我是节流') }
thro.addEventListener('mousemove', jieliu(th, 3000))


function fangdou(fn, time) {
    let timer = null;
    return function () {
        clearTimeout(timer)
        timer = setTimeout(() => {
            fn.apply(this, arguments)
        }, time)
    }
}

function jieliu(fn, time) {
    let flag = true;
    return function () {
        if (!flag) return
        flag = false
        fn.apply(this, arguments)
        setTimeout(() => {
            flag = true
        }, time)
    }
}






















